package xcmg.device.service.returnMaterial;

import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile;
import xcmg.device.dao.entity.borrowMaterial.BorrowMaterialDO;
import xcmg.device.dao.entity.borrowMaterial.BorrowMaterialDetailDO;
import xcmg.device.dao.entity.returnMaterial.ReturnMaterialDO;
import xcmg.device.dao.entity.returnMaterial.ReturnMaterialDetailDO;
import xcmg.device.dao.entity.returnMaterial.ReturnMaterialMesModel;
import xcmg.device.dao.entity.returnMaterial.ReturnMaterialPrintVO;
import xcmg.device.dao.mapper.returnMaterial.ReturnMaterialMapper;
import xcmg.device.infra.ConstantInfo;
import xcmg.device.infra.ErrorCode;
import xcmg.device.infra.FileUtil;
import xcmg.device.infra.enums.BillDesc;
import xcmg.device.service.GenDocumentService;
import xcmg.device.service.borrowMaterial.BorrowMaterialDetailService;
import xcmg.device.service.borrowMaterial.BorrowMaterialService;
import xcmg.device.service.vo.warehouse.WarehouseDeliveryAddVO;
import xcmg.device.service.vo.warehouse.WarehouseDeliveryDetailVO;
import xcmg.device.service.vo.warehouse.WarehouseDeliveryVO;
import xcmg.device.service.warehouse.WarehouseDeliveryService;
import yb.ecp.fast.feign.FastGenClient;
import yb.ecp.fast.infra.infra.ActionResult;
import yb.ecp.fast.infra.infra.PageCommonVO;
import yb.ecp.fast.infra.infra.SearchCommonVO;
import yb.ecp.fast.infra.util.PageHelperPlus;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ZHANGK
 * @since 2020/6/17
 **/
@Service
public class ReturnMaterialService {

    @Autowired
    ReturnMaterialMapper returnMaterialMapper;

    @Autowired
    FastGenClient fastGenClient;

    @Autowired
    GenDocumentService genDocumentService;

    @Autowired
    ReturnMaterialDetailService returnMaterialDetailService;

    @Autowired
    BorrowMaterialService borrowMaterialService;

    @Autowired
    BorrowMaterialDetailService borrowMaterialDetailService;

    @Value("${spring.file.download.path}")
    private String filePath;

    @Autowired
    private WarehouseDeliveryService warehouseDeliveryService;


    @Transactional(rollbackFor = Exception.class)
    public ErrorCode insert(ReturnMaterialDO returnMaterialDO) throws Exception {
//        BorrowMaterialDO aDo = borrowMaterialService.selectByCode(returnMaterialDO.getBorrowCode());
//        if (ObjectUtils.isEmpty(aDo))
//            throw new Exception("借用单号【"+returnMaterialDO.getBorrowCode()+"】不存在");
        ActionResult<String> result = fastGenClient.textGuid();
        if (result == null || result.getCode() != ErrorCode.Success.getCode()) {
            return ErrorCode.Failure;
        }
        returnMaterialDO.setId(result.getValue());
        returnMaterialDO.setCode(genDocumentService.genDocumentNo(BillDesc.ReturnMaterial, returnMaterialDO.getOrgId()));
        returnMaterialDO.setCreatedDate(new Date());
        returnMaterialDO.setReturnStatus(ConstantInfo.RETURN_STATUS_NEW);
        returnMaterialDO.setStatus(ConstantInfo.RETURN_NOT_DELIVERY.toString());
        returnMaterialDO.setAuditOpinion(null);
        returnMaterialDO.setAuditRemarks(null);
        returnMaterialMapper.insert(returnMaterialDO);

        List<ReturnMaterialDetailDO> returnMaterialDetailDOList = returnMaterialDO.getReturnMaterialDetailDOList();

        List<WarehouseDeliveryDetailVO> outDetailList = new ArrayList<>();
        for (ReturnMaterialDetailDO returnMaterialDetailDO : returnMaterialDetailDOList) {
            result = fastGenClient.textGuid();
            if (result == null || result.getCode() != ErrorCode.Success.getCode()) {
                return ErrorCode.Failure;
            }
            returnMaterialDetailDO.setId(result.getValue());
            returnMaterialDetailDO.setReturnId(returnMaterialDO.getId());
            returnMaterialDetailService.insert(returnMaterialDetailDO);

            WarehouseDeliveryDetailVO detail=new WarehouseDeliveryDetailVO();
            detail.setBusinessSingle(returnMaterialDO.getCode().substring(0, 5));
            detail.setBusinessOrder(returnMaterialDO.getCode());
            detail.setMaterialNo(returnMaterialDetailDO.getMaterialNo());
            detail.setMaterialName(returnMaterialDetailDO.getMaterialDesc());
//            detail.setMaterialType(detailVO.getMaterialsType());
//            detail.setUnit(detailVO.getUnit());
            detail.setAmount(returnMaterialDetailDO.getAmount());
            detail.setRealAmount(BigDecimal.ZERO);
            outDetailList.add(detail);
        }

        WarehouseDeliveryAddVO warehouseDeliveryAddVO = new WarehouseDeliveryAddVO();
        //增加出库记录
        WarehouseDeliveryVO deliveryVO = new WarehouseDeliveryVO();
        deliveryVO.setBusinessSingle(returnMaterialDO.getCode().substring(0,5));
        deliveryVO.setBusinessOrder(returnMaterialDO.getCode());
        deliveryVO.setWarehouseCode(returnMaterialDO.getWarehouseOut());
        deliveryVO.setInArea(returnMaterialDO.getWarehouseAreaOut());
        BigDecimal num = returnMaterialDO.getReturnMaterialDetailDOList().stream().map(ReturnMaterialDetailDO::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
        deliveryVO.setAmount(num);
        warehouseDeliveryAddVO.setHeaderInfo(deliveryVO);
        warehouseDeliveryAddVO.setDetailList(outDetailList);
        warehouseDeliveryService.add(warehouseDeliveryAddVO,returnMaterialDO.getCreatedId(),returnMaterialDO.getOrgId());

        //回写是否生成归还单标记
        if (!ObjectUtils.isEmpty(returnMaterialDO.getBorrowId())) {
            BorrowMaterialDO borrowMaterialDO = new BorrowMaterialDO();
            borrowMaterialDO.setId(returnMaterialDO.getBorrowId());
            borrowMaterialDO.setReturnMaterialFlag("1");
            borrowMaterialDO.setReturnDate(new Date());
            borrowMaterialService.updateById(borrowMaterialDO);
        }

        return ErrorCode.Success;
    }

    @Transactional(rollbackFor = Exception.class)
    public ErrorCode batchInsert(List<BorrowMaterialDO> borrowMaterialDOList, String orgId,String createdId) throws Exception {
        List<String> ids = borrowMaterialDOList.stream().map(BorrowMaterialDO::getId).collect(Collectors.toList());
        borrowMaterialDOList = borrowMaterialService.selectBatchByIds(ids);
        List<ReturnMaterialDO> insertList = Lists.newArrayList();
        List<ReturnMaterialDetailDO> detailInsertList = Lists.newArrayList();
        for (BorrowMaterialDO borrowMaterialDO : borrowMaterialDOList) {
            ReturnMaterialDO returnMaterialDO = new ReturnMaterialDO();
            BeanUtils.copyProperties(borrowMaterialDO, returnMaterialDO);
            returnMaterialDO.setBorrowCode(borrowMaterialDO.getCode());
            returnMaterialDO.setReturnBy(borrowMaterialDO.getBorrower());
            returnMaterialDO.setCreatedDate(new Date());
            returnMaterialDO.setWarehouseOut(borrowMaterialDO.getWarehouseLeadIn());
            returnMaterialDO.setWarehouseAreaOut(borrowMaterialDO.getWarehouseAreaLeadIn());
            returnMaterialDO.setReturnStatus(ConstantInfo.RETURN_STATUS_NEW);
            returnMaterialDO.setCode(genDocumentService.genDocumentNo(BillDesc.ReturnMaterial, orgId));
            ActionResult<String> result = fastGenClient.textGuid();
            if (result == null || result.getCode() != ErrorCode.Success.getCode()) {
                return ErrorCode.Failure;
            }
            returnMaterialDO.setId(result.getValue());
            insertList.add(returnMaterialDO);

            BorrowMaterialDetailDO borrowMaterialDetailDO = new BorrowMaterialDetailDO();
            borrowMaterialDetailDO.setBorrowId(borrowMaterialDO.getId());
            List<BorrowMaterialDetailDO> borrowMaterialDetailDOList = borrowMaterialDetailService.selectList(borrowMaterialDetailDO);

            List<WarehouseDeliveryDetailVO> outDetailList = new ArrayList<>();

            for (BorrowMaterialDetailDO detailDO : borrowMaterialDetailDOList) {
                ReturnMaterialDetailDO returnMaterialDetailDO = new ReturnMaterialDetailDO();
                BeanUtils.copyProperties(detailDO, returnMaterialDetailDO);
                returnMaterialDetailDO.setReturnId(returnMaterialDO.getId());
                result = fastGenClient.textGuid();
                if (result == null || result.getCode() != ErrorCode.Success.getCode()) {
                    return ErrorCode.Failure;
                }
                returnMaterialDetailDO.setId(result.getValue());
                detailInsertList.add(returnMaterialDetailDO);


                WarehouseDeliveryDetailVO detail=new WarehouseDeliveryDetailVO();
                detail.setBusinessSingle(returnMaterialDO.getCode().substring(0, 4));
                detail.setBusinessOrder(returnMaterialDO.getCode());
                detail.setMaterialNo(returnMaterialDetailDO.getMaterialNo());
                detail.setMaterialName(returnMaterialDetailDO.getMaterialDesc());
//            detail.setMaterialType(detailVO.getMaterialsType());
//            detail.setUnit(detailVO.getUnit());
                detail.setAmount(returnMaterialDetailDO.getAmount());
                detail.setRealAmount(BigDecimal.ZERO);
                outDetailList.add(detail);

            }

            WarehouseDeliveryAddVO warehouseDeliveryAddVO = new WarehouseDeliveryAddVO();

            WarehouseDeliveryVO deliveryVO = new WarehouseDeliveryVO();
            deliveryVO.setBusinessSingle(returnMaterialDO.getCode().substring(0,4));
            deliveryVO.setBusinessOrder(returnMaterialDO.getCode());
            deliveryVO.setWarehouseCode(returnMaterialDO.getWarehouseOut());
            deliveryVO.setInArea(returnMaterialDO.getWarehouseAreaOut());
            BigDecimal num = detailInsertList.stream().map(ReturnMaterialDetailDO::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
            deliveryVO.setAmount(num);
            warehouseDeliveryAddVO.setHeaderInfo(deliveryVO);
            warehouseDeliveryAddVO.setDetailList(outDetailList);
            warehouseDeliveryService.add(warehouseDeliveryAddVO,createdId,orgId);

        }
        if (!ObjectUtils.isEmpty(insertList)) {
            returnMaterialMapper.batchInsert(insertList);
        }

        if (!ObjectUtils.isEmpty(detailInsertList)) {
            returnMaterialDetailService.batchInsert(detailInsertList);
        }

        for (BorrowMaterialDO borrowMaterialDO : borrowMaterialDOList) {
            borrowMaterialDO.setReturnMaterialFlag("1");
            borrowMaterialDO.setReturnDate(new Date());
        }
        //回写借用单生成归还单标记
        borrowMaterialService.batchUpdate(borrowMaterialDOList);

        return ErrorCode.Success;
    }

    @Transactional(rollbackFor = Exception.class)
    public ErrorCode deleteById(ReturnMaterialDO returnMaterialDO, String orgId) {
        ReturnMaterialDO aDo = returnMaterialMapper.selectById(returnMaterialDO.getId());
        List<String> businessOrders = Lists.newArrayList();
        businessOrders.add(aDo.getCode());
        //删除出库记录
        warehouseDeliveryService.removeByBusinessOrders(businessOrders,orgId);
        returnMaterialMapper.deleteById(returnMaterialDO);
        ReturnMaterialDetailDO returnMaterialDetailDO = new ReturnMaterialDetailDO();
        returnMaterialDetailDO.setReturnId(returnMaterialDO.getId());
        returnMaterialDetailService.delete(returnMaterialDetailDO);

        //清除借用单，借用标记
        BorrowMaterialDO borrowMaterialDO = new BorrowMaterialDO();
        borrowMaterialDO.setCode(aDo.getBorrowCode());
        borrowMaterialDO.setReturnMaterialFlag("0");
        borrowMaterialService.updateByCode(borrowMaterialDO);
        return ErrorCode.Success;
    }

    @Transactional(rollbackFor = Exception.class)
    public ErrorCode updateById(ReturnMaterialDO returnMaterialDO) {
        returnMaterialMapper.updateById(returnMaterialDO);
        if (ObjectUtils.isEmpty(returnMaterialDO.getReturnMaterialDetailDOList())) {
            return ErrorCode.Success;
        }

        ReturnMaterialDetailDO returnMaterialDetailDO = new ReturnMaterialDetailDO();
        returnMaterialDetailDO.setReturnId(returnMaterialDO.getId());
        returnMaterialDetailService.delete(returnMaterialDetailDO);

        List<ReturnMaterialDetailDO> returnMaterialDetailDOList = returnMaterialDO.getReturnMaterialDetailDOList();
        for (ReturnMaterialDetailDO detailDO : returnMaterialDetailDOList) {
            ActionResult<String> result = fastGenClient.textGuid();
            if (result == null || result.getCode() != ErrorCode.Success.getCode()) {
                return ErrorCode.Failure;
            }
            detailDO.setId(result.getValue());
            detailDO.setReturnId(returnMaterialDO.getId());
            returnMaterialDetailService.insert(detailDO);
        }
        return ErrorCode.Success;
    }

    public PageCommonVO<ReturnMaterialDO> selectPage(SearchCommonVO<ReturnMaterialDO> condition) {
        PageCommonVO<ReturnMaterialDO> pageCommonVO = new PageCommonVO<>();
        PageHelperPlus.startPage(condition.getPageNum(), condition.getPageSize());
        if (ObjectUtils.isEmpty(condition.getSort())) {
            PageHelperPlus.orderBy("CREATED_DATE DESC");
        } else {
            PageHelperPlus.orderBy(condition.getSort());
        }
        List<ReturnMaterialDO> list = returnMaterialMapper.selectList(condition.getFilters());
        pageCommonVO.setPageInfo(new PageInfo<>(list));
        pageCommonVO.setPageInfoList(list);
        return pageCommonVO;
    }

    @Transactional
    public ErrorCode batchDelete(List<ReturnMaterialDO> returnMaterialDOList,String orgId) {
        List<String> ids = returnMaterialDOList.stream().map(ReturnMaterialDO::getId).collect(Collectors.toList());
        List<ReturnMaterialDO> list = returnMaterialMapper.selectBatchByIds(ids);
        List<String> businessNos = list.stream().map(ReturnMaterialDO::getCode).collect(Collectors.toList());
        warehouseDeliveryService.removeByBusinessOrders(businessNos, orgId);
        returnMaterialMapper.batchDelete(returnMaterialDOList);
        returnMaterialDetailService.batchDeleteByReturnId(ids);

        List<BorrowMaterialDO> borrowList = Lists.newArrayList();
        for (ReturnMaterialDO returnMaterialDO : list) {
            BorrowMaterialDO borrowMaterialDO = new BorrowMaterialDO();
            borrowMaterialDO.setCode(returnMaterialDO.getBorrowCode());
            borrowMaterialDO.setReturnMaterialFlag("0");
            borrowList.add(borrowMaterialDO);
        }
        if (!ObjectUtils.isEmpty(borrowList)) {
            borrowMaterialService.batchUpdateByCode(borrowList);
        }
        return ErrorCode.Success;
    }

    public ReturnMaterialDO selectById(String id) {
        ReturnMaterialDO returnMaterialDO = returnMaterialMapper.selectById(id);
        ReturnMaterialDetailDO returnMaterialDetailDO = new ReturnMaterialDetailDO();
        returnMaterialDetailDO.setReturnId(id);
        List<ReturnMaterialDetailDO> detailDOS = returnMaterialDetailService.selectList(returnMaterialDetailDO);
        returnMaterialDO.setReturnMaterialDetailDOList(detailDOS);
        return returnMaterialDO;
    }

    public PageCommonVO<BorrowMaterialDO> getInsertList(SearchCommonVO<BorrowMaterialDO> condition) {
        BorrowMaterialDO borrowMaterialDO = new BorrowMaterialDO();
        //borrowMaterialDO.setBorrowStatus(ConstantInfo.BORROW_STATUS_INSTOCK);
        borrowMaterialDO.setReturnMaterialFlag("0");
        borrowMaterialDO.setStatus(ConstantInfo.BORROW_ALL_INBOUND);
        condition.setFilters(borrowMaterialDO);
        return borrowMaterialService.selectList(condition);
    }

    public ErrorCode uploadImage(String id, MultipartFile file) throws Exception {
        String fileName = id + "_" + System.currentTimeMillis() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        FileUtil.uploadFile(file, filePath + "image/", fileName);
        ReturnMaterialDO returnMaterialDO = new ReturnMaterialDO();
        returnMaterialDO.setId(id);
        returnMaterialDO.setImageUrl(filePath + "image/" + fileName);
        returnMaterialDO.setImageName(fileName);
        returnMaterialMapper.updateById(returnMaterialDO);
        return ErrorCode.Success;
    }

//    public ErrorCode uploadObsImage(String id, MultipartFile file) throws Exception {
//        String fileName = id + "_" + System.currentTimeMillis() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
//        PutObjectResult putObjectResult = obsService.putObjectAndSetPreAccess(obsProperties.getDefaultBucketName(), fileName,file.getInputStream());
//        ReturnMaterialDO returnMaterialDO = new ReturnMaterialDO();
//        returnMaterialDO.setId(id);
//        returnMaterialDO.setImageUrl(putObjectResult.getObjectUrl());
//        returnMaterialDO.setImageName(fileName);
//        returnMaterialMapper.updateById(returnMaterialDO);
//        return ErrorCode.Success;
//    }

    public List<ReturnMaterialPrintVO> selectPrintList(String[] ids) {
        List<ReturnMaterialDO> returnMaterialDOList = Lists.newArrayList();
        List<ReturnMaterialPrintVO> printVOList = Lists.newArrayList();
        for (String id : ids) {
            ReturnMaterialDO returnMaterialDO = new ReturnMaterialDO();
            returnMaterialDO.setId(id);
            returnMaterialDO.setIsPrint("1");
            returnMaterialDOList.add(returnMaterialDO);
        }
        //回写是否打印标记
        returnMaterialMapper.batchUpdate(returnMaterialDOList);

        returnMaterialDOList = returnMaterialMapper.selectBatchByIds(Arrays.asList(ids));
        for (ReturnMaterialDO returnMaterialDO : returnMaterialDOList) {
            ReturnMaterialPrintVO returnMaterialPrintVO = new ReturnMaterialPrintVO();
            returnMaterialPrintVO.setHeaderInfo(returnMaterialDO);
            ReturnMaterialDetailDO returnMaterialDetailDO = new ReturnMaterialDetailDO();
            returnMaterialDetailDO.setReturnId(returnMaterialDO.getId());
            List<ReturnMaterialDetailDO> returnMaterialDetailDOList = returnMaterialDetailService.selectList(returnMaterialDetailDO);
            returnMaterialPrintVO.setMaterialList(returnMaterialDetailDOList);
            returnMaterialDO.setReturnMaterialDetailDOList(returnMaterialDetailDOList);
            printVOList.add(returnMaterialPrintVO);
        }
        return printVOList;
    }

//    @Transactional(rollbackFor = Exception.class)
//    public ErrorCode audit(ReturnMaterialDO returnMaterialDO) throws Exception {
//        boolean result = returnMaterialMapper.updateById(returnMaterialDO);
//        if (result) {
//            returnMaterialDO = returnMaterialMapper.selectById(returnMaterialDO.getId());
//            ReturnMaterialDetailDO returnMaterialDetailDO = new ReturnMaterialDetailDO();
//            returnMaterialDetailDO.setReturnId(returnMaterialDO.getId());
//            List<ReturnMaterialDetailDO> returnMaterialDetailDOList = returnMaterialDetailService.selectList(returnMaterialDetailDO);
//            if (ObjectUtils.isEmpty(returnMaterialDetailDOList))
//                throw new Exception("零件明细为空");
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//            ReturnMaterialMesModel returnMaterialMesModel = new ReturnMaterialMesModel();
//            BeanUtils.copyProperties(returnMaterialDO, returnMaterialMesModel);
//            returnMaterialMesModel.setReturnDate(sdf.format(returnMaterialDO.getCreatedDate()));
//            returnMaterialMesModel.setAmount(returnMaterialDetailDOList.get(0).getAmount());
//
//            //调用MES接口，抛数据给MES
//            List<ReturnMaterialMesModel> param = Lists.newArrayList();
//            param.add(returnMaterialMesModel);
//            Map resultMap = mesClient.insertMaterialReturn(param);
//            String code = resultMap.get("code").toString();
//            if (!code.equals("200")) {
//                String message = resultMap.get("message").toString();
//                throw new Exception("同步mes失败，原因:" + message);
//            }
//        }
//        return ErrorCode.Success;
//    }


    @Transactional(rollbackFor = Exception.class)
    public boolean updateByOutbound(String businessOrder, String materialNo, BigDecimal realAmount, Integer singleState, Integer totalState, String orgId) {
        ReturnMaterialDO returnMaterialDO = new ReturnMaterialDO();
        returnMaterialDO.setCode(businessOrder);
        returnMaterialDO.setStatus(String.valueOf(totalState));
        returnMaterialMapper.updateByCode(returnMaterialDO);

        //回写借用单出库时间为当前时间
        List<ReturnMaterialDO> returnMaterialDOList = returnMaterialMapper.selectList(returnMaterialDO);
        if (returnMaterialDOList.size() > 0){
            returnMaterialDO = returnMaterialDOList.get(0);
            BorrowMaterialDO borrowMaterialDO = new BorrowMaterialDO();
            borrowMaterialDO.setCode(returnMaterialDO.getBorrowCode());
            borrowMaterialDO.setDeliveryDate(new Date());
            borrowMaterialService.updateByCode(borrowMaterialDO);
        }
        return true;
    }

    @Transactional(rollbackFor = Exception.class)
    public ErrorCode finish(ReturnMaterialDO returnMaterialDO) throws Exception {
        boolean result = returnMaterialMapper.updateById(returnMaterialDO);
        if (result) {
            returnMaterialDO = returnMaterialMapper.selectById(returnMaterialDO.getId());
            ReturnMaterialDetailDO returnMaterialDetailDO = new ReturnMaterialDetailDO();
            returnMaterialDetailDO.setReturnId(returnMaterialDO.getId());
            List<ReturnMaterialDetailDO> returnMaterialDetailDOList = returnMaterialDetailService.selectList(returnMaterialDetailDO);
            if (ObjectUtils.isEmpty(returnMaterialDetailDOList)) {
                throw new Exception("零件明细为空");
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            ReturnMaterialMesModel returnMaterialMesModel = new ReturnMaterialMesModel();
            BeanUtils.copyProperties(returnMaterialDO, returnMaterialMesModel);
            returnMaterialMesModel.setReturnDate(sdf.format(returnMaterialDO.getCreatedDate()));
            returnMaterialMesModel.setAmount(returnMaterialDetailDOList.get(0).getAmount());
            returnMaterialMesModel.setCode(returnMaterialDO.getBorrowCode());

//            //调用MES接口，抛数据给MES
//            List<ReturnMaterialMesModel> param = Lists.newArrayList();
//            param.add(returnMaterialMesModel);
//            LogHelper.monitor("归还单完成同步mes,请求入参"+ JsonUtil.objectToString(param));
//            Map resultMap = mesClient.insertMaterialReturn(param);
//            LogHelper.monitor("归还单完成同步mes,返回结果"+ JsonUtil.objectToString(resultMap));
//            String code = resultMap.get("code").toString();
//            if (!code.equals("200")) {
//                String message = resultMap.get("message").toString();
//                throw new Exception("同步mes失败，原因:" + message);
//            }
        }
        return ErrorCode.Success;
    }
}
